Skip to content

fix(ui): pin NODE_ENV=test in vitest config (RAN-40)#81

Merged
aksOps merged 1 commit intomainfrom
fix/test-node-env-ran40
Apr 25, 2026
Merged

fix(ui): pin NODE_ENV=test in vitest config (RAN-40)#81
aksOps merged 1 commit intomainfrom
fix/test-node-env-ran40

Conversation

@aksOps
Copy link
Copy Markdown
Contributor

@aksOps aksOps commented Apr 25, 2026

Summary

  • React 19's CJS entry picks production vs development at require-time off process.env.NODE_ENV; the production build omits act, which @testing-library/react needs. Shells that export NODE_ENV=production (CI-adjacent shells, the Paperclip agent harness) silently fail 78/97 tests with TypeError: React.act is not a function. CI runners (NODE_ENV unset) are unaffected.
  • Vitest's own process.env.NODE_ENV ||= 'test' only fires when NODE_ENV is unset, and --mode test does not override an already-set NODE_ENV in vitest 4. Forcing process.env.NODE_ENV = 'test' at the top of vitest.config.ts (before any worker forks) makes the suite deterministic regardless of caller env. No new dependencies.

Test plan

  • NODE_ENV=production npm --prefix ui run test → 97/97 pass
  • NODE_ENV=production npm --prefix ui run test:coverage → 97/97 pass, coverage report generated
  • NODE_ENV=test npm --prefix ui run test → 97/97 pass
  • NODE_ENV unset, npm --prefix ui run test → 97/97 pass (CI parity)
  • CI ui (build + test + budget) job stays green

Closes RAN-40.

…RAN-40)

React 19 ships separate CJS builds and selects between them via
process.env.NODE_ENV at require-time; the production build omits `act`,
which @testing-library/react needs. Any developer whose shell exports
NODE_ENV=production (CI-adjacent shells, the Paperclip agent harness, etc.)
would see 78/97 tests fail with `TypeError: React.act is not a function`,
even though CI runners (NODE_ENV unset) pass.

Vitest already does `process.env.NODE_ENV ||= 'test'`, but only when unset;
when it's already `production` it's preserved, hence the bug. `--mode test`
also doesn't override an already-set NODE_ENV in vitest 4.

Force NODE_ENV=test at the top of vitest.config.ts before any worker forks
so the test suite is deterministic regardless of caller env.

Verified locally:
- NODE_ENV=production npm --prefix ui run test → 97/97 pass
- NODE_ENV=production npm --prefix ui run test:coverage → coverage generated
- NODE_ENV unset npm --prefix ui run test → 97/97 pass (CI parity)

Co-Authored-By: Paperclip <noreply@paperclip.ing>
Copy link
Copy Markdown
Contributor Author

@aksOps aksOps left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TechLead merge-gate review (non-approving — GitHub blocks self-approval since gh auth is the same user). Reviewed against RAN-40 acceptance criteria; all three signals met. Scope, side-effects, cross-platform, deps, and reasoning all clean. Squash-merging.

@aksOps aksOps merged commit 0bd76ea into main Apr 25, 2026
12 checks passed
@aksOps aksOps deleted the fix/test-node-env-ran40 branch April 25, 2026 15:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant